from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-30 14:02:41.149260
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 30, Dec, 2022
Time: 14:02:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3283
Nobs: 886.000 HQIC: -51.6286
Log likelihood: 11729.2 FPE: 3.14233e-23
AIC: -51.8145 Det(Omega_mle): 2.84042e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297793 0.049305 6.040 0.000
L1.Burgenland 0.105872 0.033845 3.128 0.002
L1.Kärnten -0.106645 0.018174 -5.868 0.000
L1.Niederösterreich 0.213341 0.070971 3.006 0.003
L1.Oberösterreich 0.083635 0.067122 1.246 0.213
L1.Salzburg 0.250626 0.035944 6.973 0.000
L1.Steiermark 0.029342 0.047178 0.622 0.534
L1.Tirol 0.127015 0.038357 3.311 0.001
L1.Vorarlberg -0.061888 0.033008 -1.875 0.061
L1.Wien 0.065158 0.059883 1.088 0.277
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062273 0.101253 0.615 0.539
L1.Burgenland -0.009252 0.069505 -0.133 0.894
L1.Kärnten 0.049300 0.037322 1.321 0.187
L1.Niederösterreich -0.170947 0.145748 -1.173 0.241
L1.Oberösterreich 0.360514 0.137844 2.615 0.009
L1.Salzburg 0.285804 0.073816 3.872 0.000
L1.Steiermark 0.107710 0.096885 1.112 0.266
L1.Tirol 0.319332 0.078772 4.054 0.000
L1.Vorarlberg 0.025401 0.067786 0.375 0.708
L1.Wien -0.024296 0.122978 -0.198 0.843
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201265 0.025645 7.848 0.000
L1.Burgenland 0.090458 0.017604 5.139 0.000
L1.Kärnten -0.008845 0.009453 -0.936 0.349
L1.Niederösterreich 0.267407 0.036915 7.244 0.000
L1.Oberösterreich 0.110803 0.034913 3.174 0.002
L1.Salzburg 0.053590 0.018696 2.866 0.004
L1.Steiermark 0.015204 0.024539 0.620 0.536
L1.Tirol 0.101729 0.019951 5.099 0.000
L1.Vorarlberg 0.056921 0.017169 3.315 0.001
L1.Wien 0.112452 0.031147 3.610 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105154 0.026293 3.999 0.000
L1.Burgenland 0.048302 0.018049 2.676 0.007
L1.Kärnten -0.016369 0.009692 -1.689 0.091
L1.Niederösterreich 0.197873 0.037847 5.228 0.000
L1.Oberösterreich 0.276380 0.035795 7.721 0.000
L1.Salzburg 0.117829 0.019168 6.147 0.000
L1.Steiermark 0.100507 0.025158 3.995 0.000
L1.Tirol 0.125179 0.020455 6.120 0.000
L1.Vorarlberg 0.070142 0.017602 3.985 0.000
L1.Wien -0.025845 0.031934 -0.809 0.418
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132848 0.047355 2.805 0.005
L1.Burgenland -0.053687 0.032506 -1.652 0.099
L1.Kärnten -0.036454 0.017455 -2.088 0.037
L1.Niederösterreich 0.166369 0.068164 2.441 0.015
L1.Oberösterreich 0.132784 0.064468 2.060 0.039
L1.Salzburg 0.290608 0.034523 8.418 0.000
L1.Steiermark 0.033071 0.045312 0.730 0.465
L1.Tirol 0.160161 0.036840 4.347 0.000
L1.Vorarlberg 0.108360 0.031703 3.418 0.001
L1.Wien 0.067501 0.057515 1.174 0.241
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064644 0.037617 1.718 0.086
L1.Burgenland 0.038529 0.025822 1.492 0.136
L1.Kärnten 0.050003 0.013866 3.606 0.000
L1.Niederösterreich 0.226019 0.054148 4.174 0.000
L1.Oberösterreich 0.266951 0.051212 5.213 0.000
L1.Salzburg 0.060931 0.027424 2.222 0.026
L1.Steiermark -0.007018 0.035995 -0.195 0.845
L1.Tirol 0.157333 0.029265 5.376 0.000
L1.Vorarlberg 0.067709 0.025184 2.689 0.007
L1.Wien 0.075667 0.045689 1.656 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188305 0.045221 4.164 0.000
L1.Burgenland 0.017589 0.031042 0.567 0.571
L1.Kärnten -0.058704 0.016669 -3.522 0.000
L1.Niederösterreich -0.096170 0.065093 -1.477 0.140
L1.Oberösterreich 0.177621 0.061563 2.885 0.004
L1.Salzburg 0.061380 0.032967 1.862 0.063
L1.Steiermark 0.225935 0.043270 5.222 0.000
L1.Tirol 0.483666 0.035180 13.748 0.000
L1.Vorarlberg 0.052263 0.030274 1.726 0.084
L1.Wien -0.050174 0.054924 -0.914 0.361
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153837 0.051120 3.009 0.003
L1.Burgenland -0.000698 0.035091 -0.020 0.984
L1.Kärnten 0.066868 0.018843 3.549 0.000
L1.Niederösterreich 0.201456 0.073584 2.738 0.006
L1.Oberösterreich -0.067400 0.069594 -0.968 0.333
L1.Salzburg 0.221156 0.037268 5.934 0.000
L1.Steiermark 0.108395 0.048914 2.216 0.027
L1.Tirol 0.084199 0.039769 2.117 0.034
L1.Vorarlberg 0.126242 0.034223 3.689 0.000
L1.Wien 0.107254 0.062088 1.727 0.084
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358590 0.030262 11.850 0.000
L1.Burgenland 0.007683 0.020773 0.370 0.711
L1.Kärnten -0.025455 0.011154 -2.282 0.022
L1.Niederösterreich 0.229937 0.043560 5.279 0.000
L1.Oberösterreich 0.152162 0.041197 3.693 0.000
L1.Salzburg 0.052536 0.022061 2.381 0.017
L1.Steiermark -0.017530 0.028956 -0.605 0.545
L1.Tirol 0.122248 0.023542 5.193 0.000
L1.Vorarlberg 0.072118 0.020259 3.560 0.000
L1.Wien 0.049235 0.036754 1.340 0.180
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039146 0.164084 0.183313 0.170467 0.146243 0.130627 0.067290 0.220405
Kärnten 0.039146 1.000000 0.002678 0.132644 0.027540 0.099145 0.430729 -0.048620 0.101897
Niederösterreich 0.164084 0.002678 1.000000 0.349886 0.173641 0.318098 0.135031 0.194018 0.342174
Oberösterreich 0.183313 0.132644 0.349886 1.000000 0.236606 0.344464 0.183798 0.180378 0.274467
Salzburg 0.170467 0.027540 0.173641 0.236606 1.000000 0.156649 0.141055 0.154159 0.141776
Steiermark 0.146243 0.099145 0.318098 0.344464 0.156649 1.000000 0.165818 0.148694 0.098324
Tirol 0.130627 0.430729 0.135031 0.183798 0.141055 0.165818 1.000000 0.125466 0.165448
Vorarlberg 0.067290 -0.048620 0.194018 0.180378 0.154159 0.148694 0.125466 1.000000 0.021464
Wien 0.220405 0.101897 0.342174 0.274467 0.141776 0.098324 0.165448 0.021464 1.000000